package org.example.util;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

public class JedisConnectionFactory {
    private static final String REDIS_HOST = "192.168.249.128";
    private static final int REDIS_PORT = 6379;
    private static final String REDIS_PASSWORD = "123456";

    private static final JedisPool jedisPool;

    static {
        JedisPoolConfig config = new JedisPoolConfig();
        config.setMaxTotal(8);// 最大连接数
        config.setMaxIdle(8);// 最大空闲连接数
        config.setMinIdle(0);// 最小空闲连接数
        config.setMaxWaitMillis(200);// 最大等待时间,单位毫秒
        jedisPool = new JedisPool(config, REDIS_HOST, REDIS_PORT, 2000, REDIS_PASSWORD);
    }

    // 获取Jedis实例
    public static Jedis getJedis() {
        return jedisPool.getResource();
    }
}
